package com.example.demo1.conrtoller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/redis")
public class RedisTest1 {

    @Autowired
    @Qualifier("singletonRedisTemplate")
    private RedisTemplate singletonRedisTemplate;

//    @Autowired
//    @Qualifier("redisTemplate")
//    private RedisTemplate redisTemplate;

    @RequestMapping(value = "/redisTest1", method= {RequestMethod.POST, RequestMethod.GET})
    public String redisTest1() {

        singletonRedisTemplate.opsForSet().add("names", "baohuajie");
        singletonRedisTemplate.opsForSet().add("names", "baohuajie1");

//        redisTemplate.opsForSet().add("names", "baohuajie");
//        redisTemplate.opsForSet().add("names", "baohuajie1");
        return "baohuajie";
    }

    @RequestMapping(value = "/redisTest2", method= {RequestMethod.POST, RequestMethod.GET})
    public String redisTest2() {
        HashOperations hashOperations = singletonRedisTemplate.opsForHash();

        try {
            Map map = new HashMap();

            for (int i = 0; i < 1000000; i ++ ) {
                map.put("baohuajie" + String.valueOf(i), "baohuajie" + String.valueOf(i));
            }
            hashOperations.putAll("namesTemp", map);
        } finally {


        }


//        redisTemplate.opsForSet().add("names", "baohuajie");
//        redisTemplate.opsForSet().add("names", "baohuajie1");
        return "baohuajie";
    }
}
